package com.firewolf.springboot.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import com.firewolf.springboot.beans.Student;
import com.firewolf.springboot.dao.StudentRespository;

@Service
public class StudentServiceImpl {
	
	@Autowired
	private StudentRespository sDao;
	
	@Autowired
	private RedisTemplate<String, String> redisTemplate;
	
	public String redisTest(){
		redisTemplate.opsForValue().set("001", "zhangsan");
		return "true";
	}
	
	@Cacheable(value="stus")
	public Student findById(long id) {
		System.out.println("从数据库查询数据");
		return sDao.findOne(id);
	}

	//这次在重写了缓存配置的keygenerator方法之后，导致清除缓存失败了，因为此时的key是com.firewolf.springboot.service.impl.StudentServiceImpldeleteFromCache1
	//而不是存入的key：com.firewolf.springboot.service.impl.StudentServiceImplfindById1
	@CacheEvict(value= "stus")
	public void deleteFromCache(long id) {
		
	}

	public void batchSave(List<Student> sList) {
		sDao.save(sList);
	}


}
